/**
 * test case for api_account_detail
 */
describe("api_account_detail", function() {
	beforeEach(function() {
		App.initSession();
	});

	describe('bsoi accountDetail', function() {
		var account = App.HaveAccount.create();
		var callback = jasmine.createSpy();
		var accountDetailResponse, cardDetailResponse, loanDetailResponse;
		beforeEach(function() {
			accountDetailResponse = {
				    "accountDetailResponse": {
				        "account": {
				            "localCurrentBalance": 510.62,
				            "localAvailableBalance": 510.62,
				            "principal": 0,
				            "term": "",
				            "interestRate": 0,
				            "interestAtMaturity": 0,
				            "maturityAmount": 0,
				            "termCode": "",
				            "interestDisposalCode": "",
				            "principalDisposalCode": "",
				            "productCategory": "CASA",
				            "productCode": "DDA",
				            "subProductCode": "159",
				            "accountNumber": "22506104458",
				            "accountName": "NRO Liason Office C/A",
				            "accountDescription": "NRO Liason Office C/A",
				            "currencyCode": "INR",
				            "currentBalance": 510.62,
				            "availableBalance": 510.62,
				            "onlineFlag": false,
				            "productGroup": "STMT",
				            "accountType": "NRO Liason Office C/A",
				            "accountNumberDisplay": "NRO Liason Office C/A",
				            "productDescription": "Current Account"
				        },
				        "responseHeader": {
				            "status": 1,
				            "currentTimestamp": "2012-05-30T15:13:39.275+0530",
				            "nonce": "2ddc2e9a7ebaadcddf091a4b3e8de397"
				        }
				    }
				};
			cardDetailResponse = {
				    "cardDetailResponse": {
				        "card": {
				            "cardType": "   ",
				            "cardStatus": "1",
				            "statementBalance": -232886.7,
				            "outStandingBalance": -232886.7,
				            "availableCreditLimit": 310000,
				            "minimumAmountDue": 0,
				            "paymentDueDate": "2009-08-21T00:00:00.000+0530",
				            "pastDueFlag": "",
				            "productCategory": "CARD",
				            "productCode": "CCA",
				            "subProductCode": "230",
				            "accountNumber": "4563982000385591",
				            "accountDescription": "Visa Silver International",
				            "currencyCode": "INR",
				            "currentBalance": -232886.7,
				            "availableBalance": 542886.7,
				            "onlineFlag": true,
				            "productGroup": "CARD",
				            "accountType": "Visa Silver International",
				            "accountNumberDisplay": "Visa Silver International",
				            "productDescription": "Credit Card Account",
				            "productIndex": "C-0"
				        },
				        "responseHeader": {
				            "status": 1,
				            "currentTimestamp": "2012-05-30T14:48:23.626+0530",
				            "nonce": "b862cd7fb562a0884f543f3981675466"
				        }
				    }
				};
			
			loanDetailResponse = {
			    "loanDetailResponse": {
			        "loan": {
			            "installmentAmount": 84469,
			            "borrowerName": "CDUDM RGOG                              ",
			            "overDueBalance": 170810.68,
			            "applicationAmount": 6438416.66,
			            "nextDueDate": "2011-11-18T00:00:00.000+0530",
			            "maturityDate": "2034-08-18T00:00:00.000+0530",
			            "repaymentFrequency": "M",
			            "loanTenor": "276",
			            "remainingTenor": "0274",
			            "interestRate": 15.26,
			            "applicationDate": "2011-08-18T00:00:00.000+0530",
			            "approvalDate": "2011-08-18T00:00:00.000+0530",
			            "productCategory": "LOAN",
			            "productCode": "RLA",
			            "subProductCode": "HL",
			            "accountNumber": "06348350095",
			            "accountDescription": "LARP                          ",
			            "accountStatus": "60",
			            "currencyCode": "INR",
			            "currentBalance": 6604006.75,
			            "onlineFlag": false,
			            "productGroup": "LOAN",
			            "accountType": "Home Loans",
			            "accountNumberDisplay": "LARP                          ",
			            "productDescription": "LOAN ACCOUNT"
			        },
			        "responseHeader": {
			            "status": 1,
			            "currentTimestamp": "2012-05-30T15:20:23.452+0530",
			            "nonce": "a625f3e41ac8ce7c0a8174aacbb36685"
			        }
			    }
			};
		
			spyOn(bsoi, "accountDetail").andCallFake(function() {

				App.api_accountDetail._processAccountDetail(accountDetailResponse);
			});
		});

		it('User can get account detail', function() {
			spyOn(account, "getProductVO");
			spyOn(App.api_accountDetail, "_processAccountDetail");

			App.api_accountDetail.getAccountDetails(account, callback);
			
			expect(App.api_accountDetail.callbackAccountDetails).toEqual(callback);
			expect(bsoi.accountDetail).toHaveBeenCalled();
			
			expect(App.api_accountDetail._processAccountDetail).toHaveBeenCalledWith(accountDetailResponse);
		});
		
		it('Have account instance shoud be updated with processAccountDetail', function(){
			var t_haveAccount = App.HaveAccount.create();
			t_haveAccount.currentBalance = 0.0;
			App.api_accountDetail.callbackAccountDetails = function(){
				expect(t_haveAccount.currentBalance).toEqual(510.62);
			};
			App.api_accountDetail._processAccountDetail(accountDetailResponse, t_haveAccount);
			
		});
		
		it('Have card instance shoud be updated with processCardDetail', function(){
			var t_cardAccount = App.CardAccount.create();
			t_cardAccount.currentBalance = 200;
			
			App.api_accountDetail.callbackAccountDetails = function(){
				expect(t_cardAccount.currentBalance).toEqual(-232886.7);
			};
			App.api_accountDetail._processCardDetail(cardDetailResponse, t_cardAccount);
			
		});
		
		it('Have loan instance shoud be updated with processLoanDetail', function(){
			var t_loanAccount = App.LoanAccount.create();
			t_loanAccount.installmentAmount = 0;
			
			App.api_accountDetail.callbackAccountDetails = function(){
				expect(t_loanAccount.installmentAmount).toEqual(loanDetailResponse.loanDetailResponse.loan.installmentAmount);
			};
			App.api_accountDetail._processLoanDetail(loanDetailResponse, t_loanAccount);
			
		});
		
	});
	
	describe('bsoi accountDetail error', function() {
		var accountError, cardError, loanError;
		beforeEach(function(){
			accountError = {
				    "accountDetailResponse": {
				        "responseHeader": {
				            "status": 0,
				            "errorCode": "ERR_NO_ACCOUNT_FOUND",
				            "errorMessage": "Sorry, we are unable to process your request at this time. Should you require immediate assistance, please contact Phone Banking or write to us at customer.care@sc.com (Err Code:2000)",
				            "currentTimestamp": "2012-05-30T16:25:26.004+0530",
				            "nonce": "861fbc4426a4faa865913a40e0c49ed7"
				        }
				    }
				};
			cardError = {
				    "cardDetailResponse": {
				        "responseHeader": {
				            "status": 0,
				            "errorCode": "ERR_NO_ACCOUNT_FOUND",
				            "errorMessage": "Sorry, we are unable to process your request at this time. Should you require immediate assistance, please contact Phone Banking or write to us at customer.care@sc.com (Err Code:2000)",
				            "currentTimestamp": "2012-05-30T16:12:58.828+0530",
				            "nonce": "cd4df9c99af080eee75f0b5bff78c2f2"
				        }
				    }
				};
			loanError = {
				    "loanDetailResponse": {
				        "responseHeader": {
				            "status": 0,
				            "errorCode": "ERR_NO_ACCOUNT_FOUND",
				            "errorMessage": "Sorry, we are unable to process your request at this time. Should you require immediate assistance, please contact Phone Banking or write to us at customer.care@sc.com (Err Code:2000)",
				            "currentTimestamp": "2012-05-30T16:26:50.568+0530",
				            "nonce": "eff971bb0413934ed40b80ade05ec6aa"
				        }
				    }
				};
		});
		
		it('Should get BreezeException with response error', function(){
			App.api_accountDetail.callbackAccountDetails = function(account, error){
				expect(error.getErrorCode()).toEqual('ERR_NO_ACCOUNT_FOUND');
			};
			
			App.api_accountDetail._processAccountDetail(accountError, null);
			App.api_accountDetail._processCardDetail(cardError, null);
			App.api_accountDetail._processLoanDetail(loanError, null);
			
		});
	});

});
